{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-24T08:51:11.211752Z",
     "start_time": "2020-04-24T08:51:11.207397Z"
    }
   },
   "outputs": [],
   "source": [
    "import glob\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-24T09:28:10.351501Z",
     "start_time": "2020-04-24T09:28:09.341801Z"
    }
   },
   "outputs": [],
   "source": [
    "img_src = glob.glob(\"./bdd100k/images/100k/train/*.jpg\")\n",
    "xml_src = glob.glob(\"./bdd100k/xml/train/*.xml\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-24T09:30:48.983535Z",
     "start_time": "2020-04-24T09:30:48.539137Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "70000\n"
     ]
    }
   ],
   "source": [
    "img_name = []\n",
    "\n",
    "num_img = 0\n",
    "for img in img_src:\n",
    "    num_img += 1\n",
    "    img_basename = os.path.basename(img)\n",
    "    img_onlyname = os.path.splitext(img_basename)\n",
    "\n",
    "    img_name.append(img_onlyname[0])\n",
    "    \n",
    "print(num_img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-24T09:31:28.844580Z",
     "start_time": "2020-04-24T09:31:28.395349Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "69863\n"
     ]
    }
   ],
   "source": [
    "xml_name = []\n",
    "\n",
    "num_xml = 0\n",
    "for xml in xml_src:\n",
    "    num_xml += 1\n",
    "    xml_basename = os.path.basename(xml)\n",
    "    xml_onlyname = os.path.splitext(xml_basename)\n",
    "\n",
    "    xml_name.append(xml_onlyname[0])\n",
    "    \n",
    "print(num_xml)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-24T09:33:31.166331Z",
     "start_time": "2020-04-24T09:31:48.552960Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "137\n"
     ]
    }
   ],
   "source": [
    "not_in_list = []\n",
    "\n",
    "for img in img_name:\n",
    "    if img not in xml_name: not_in_list.append(img)\n",
    "\n",
    "print(len(not_in_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-24T09:33:47.802092Z",
     "start_time": "2020-04-24T09:33:47.786860Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['7360cc7a-138da2b5', '6b1f5022-48037f59', '621a49b2-0b00f7bd', '64a355f1-02850b31', '58208859-5316743a', '7832d791-a1efbf0d', '7a53506f-9c59128b', '73e07d14-c2d2f031', '5ea6db6f-fa6b86fb', '6fdb819f-ce21ee5f', '7adaeab3-10ec73b5', '61676670-5ddf4aa4', '71be111b-3d2c42bf', '6521230a-c379ab8a', '6731a55a-3ecf9a1d', '66838ab6-1d4062e5', '65551742-016ff56a', '659a7a5e-92995bc3', '5d1905d8-875b2482', '72024824-3cf37c08', '5d178102-9d5e50e2', '772eca25-a718f498', '7085ac8a-afc1e733', '57dd03e1-7b415b61', '76a40920-fc78b7cf', '6235309f-a5cc4d73', '7a85221a-9b83dce8', '681943bb-77050ee3', '7cddaf5e-2bdf3965', '73918596-79c9e945', '7a36201f-1b550e67', '6f7184c4-e7ec2226', '6e0fa2a3-a8f2be95', '5f9e9266-78dac9cc', '65e0a5b6-08d3611c', '612affad-42702404', '79df0f3c-f11ba259', '54ea83be-ce461fd7', '66644eeb-b3f4ee0e', '62bd3830-aa6cb431', '5cc5736c-1b3b8a9b', '68ce94b4-855f26a3', '5de74ad7-9f445ae3', '5dc66059-52bfaff7', '7b0114cd-55ad1f37', '69519e0a-60b2fb72', '7d2efdc4-6e8949dc', '6032f7e2-a7062c48', '573809a9-e5a1b3b8', '5ee6af4d-b34992f0', '5b6dfbed-ea08eb7b', '7afd081d-1b76748c', '7944f396-18fb3eba', '77c27140-244a8a88', '77d72c41-7e2d85d5', '5de4c788-84dbc745', '5b7255d9-350ca0b7', '60855380-49af8931', '63ff2a76-e232da16', '68aca905-2c504ffd', '75e66365-45cebb67', '6d3eab65-1a1f9a3b', '7df1ba2b-66efeea0', '5c99e5ec-7aed1c3f', '608640e2-c900aca1', '76b72431-735ebc8f', '6051b591-f7ec53c8', '5811624d-0c858bd8', '5b1b0c34-216cd6a5', '6a76c075-d995ef0a', '679c58f7-e9a258c2', '79bb5311-1819cfb5', '765f15fb-ef824308', '75417b66-b26413f4', '79a6c89a-342f4751', '5b4727ac-d3fd8666', '5ccd45ac-62dae534', '7764bde0-03b1070a', '74c17dc8-5da29363', '67c665d7-5d43cd3d', '66fab43d-46c5b8f2', '5691a2c2-59c9f7ed', '5ee9e8f1-c1cd62b8', '7ddc420d-256fa72d', '68c29514-3c867490', '6fe61342-4d182f3a', '7c6fa554-0c165e4f', '6188d9b2-08ac3765', '749161f9-5281a0e0', '5b97b4c1-455baf62', '69ebe4cd-d5567704', '61239730-1811efc0', '6a42c0ab-5a1df402', '67aafe4e-ba113a20', '70cc96e1-1802a164', '6e9e3de7-318e1e75', '641d1337-af06cf4e', '6d95cfb2-60926d6d', '6a90b276-de74a29c', '6cf7a093-29129f20', '5cf522b8-a0144375', '5e412e85-d1452b76', '6bc8a49b-b03d2226', '718c99cd-80508f57', '56bcdb00-0a1074d2', '66ed92d6-a7529a59', '734ecaa0-995f18ad', '647e8e1c-0141c492', '69687999-3bd919f4', '5797f14c-159e4924', '64c28530-3876deb2', '7751b61d-71561cda', '63ab7273-cc691816', '5e464562-65962983', '5ead49a0-f0566b6a', '5fdc609c-d87d775f', '738820d1-958724b2', '60595c14-113d4b8c', '5cd4c6d7-2051e443', '5ee6af4d-e02b3213', '78c24fcc-bfe7d2da', '69061757-1459064f', '6fcbd17b-9cd6c3a2', '6739851f-37c84296', '7809356e-8e74fe0a', '5c4991da-2bcce0d1', '7481cb59-0c09de18', '796e51dd-c9ed72e3', '5b54f9f0-848cd09b', '6f0cc882-8b3e2238', '7da4529f-fda6359b', '7aca5bc0-23859d6f', '75b44995-fef0153f', '66753960-186df654', '66cbb16a-010edd6c', '75f56250-ee873a57', '67c665d7-662c6e08']\n"
     ]
    }
   ],
   "source": [
    "print(not_in_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-24T09:37:12.598889Z",
     "start_time": "2020-04-24T09:37:12.587617Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "./bdd100k/images/100k/train/7360cc7a-138da2b5.jpg\n"
     ]
    }
   ],
   "source": [
    "path = \"./bdd100k/images/100k/train/\" + not_in_list[0] + \".jpg\"\n",
    "print(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-24T09:38:42.008816Z",
     "start_time": "2020-04-24T09:38:41.982996Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "137\n"
     ]
    }
   ],
   "source": [
    "# Remove training samples which do not have anotation.\n",
    "\n",
    "count = 0\n",
    "for item in not_in_list:\n",
    "    path = \"./bdd100k/images/100k/train/\" + item + \".jpg\"\n",
    "    if os.path.exists(path):\n",
    "        os.remove(path)\n",
    "        count += 1\n",
    "    else:\n",
    "        print(\"The file does not exist\")\n",
    "        \n",
    "print(count)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
